/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.core;

 import CBFSMS.*;
import com.entidades.Cliente;
import com.entidades.Pacote;

/**
 *
 * @author Ricardo
 */
public class WebGatewaySMS {


    /* Username and password of your CardBoardFish HTTPSMS account */
    private static final String username = "d2d01";
    private static final String password = "RnDjrFn5";


     /*public static String envia(List<Pacote> listaPacotes, Cliente c) {
         return "";
     }*/


    public static String envia(Pacote p, Cliente c) {

        String retorno= "ok";
        try {
            SendSMS.initialise(username, password);

            String numero = p.getNumero();
            numero = numero.replace("(", "");
            numero = numero.replace(")", "");
            numero = numero.replace("-", "");
            numero = "55"+numero; //TODO só Brasil por enquanto
            String destination = numero;
            String source      = c.getNome();
            String message     = p.getMensagem();
            int response = SendSMS.sendSMS(destination, source, message);
           
            
            /* Print the responses to the screen */
            System.out.println("\t" + response);

            if(response==SendSMS.INVALID_DEST||response==SendSMS.RETRIED_AND_FAILED){
                 retorno = "erro";
            }


         } catch (SMSClientException e) {
            System.err.println(e.getMessage());
            retorno = "erro";
         }

        return retorno;
    }

    public static void main(String[] args) {
        try {
            /* Initialise the library */
            System.out.println("Initialising library...");
            SendSMS.initialise(username, password);
            System.out.println("Library initialised.");

            /* Send a message to 447000000001 with sender 'James' and message 'Hello'. SourceTON (type of number) will be set automatically by the lobrary. */

            /* This could be given as a single string, in which case
               the sendSMS method returns a single integer. */
            String[] destination = { "553188927434" };
            String source      = "Ricardo";
            String message     = "teste";
            System.out.println("Sending message...");
            int[] responses = SendSMS.sendSMS(destination, source, message);
            System.out.println("Message sent.");

            /* Print the responses to the screen */
            System.out.println("Responses from the server:");
            for (int i = 0; i < responses.length; i++) {
                System.out.println("\t" + responses[i]);
            }

        } catch (SMSClientException e) {
            System.err.println(e.getMessage());
        }
    }






}
